home *** CD-ROM | disk | FTP | other *** search
/ Run Magazine ReRun 1991 September & October / rerun-1991-09-10.d64 / number convert (.txt) < prev    next >
Commodore BASIC  |  2022-09-20  |  11KB  |  391 lines

  1. 5 goto40
  2. 10 poke 53281,0
  3. 15 p$="menu runner":print"[147]"
  4. 17 printtab(14)"[159]loading me[158]n[159]u":print"[144]load"chr$(34)p$chr$(34)",8"
  5. 20 poke 198,4:poke 631,13:poke 632,82:poke 633,213:poke 634,13:end
  6. 25 print"[147]":poke 53280,14:poke 53281,14:sys 64738
  7. 30 printtab(w+len(s$))"[145] [157]":s$="":return
  8. 35 printtab(w)"[145]                 [157][157][157][157][157][157][157][157][157][157][157][157][157][157][157][157][157]";:return
  9. 40 sd=54272:fori=sdtosd+23:pokei,0:next:pokesd+24,15
  10. 45 poke53280,5:poke53281,0:poke788,52:print chr$(142);chr$(8)
  11. 50 print"[147]  1) decimal to binary conversion"
  12. 55 print"  2) binary to decimal conversion"
  13. 60 print"  3) decimal to hexadecimal conversion"
  14. 65 print"  4) hexadecimal to decimal conversion"
  15. 70 print"  5) rectangular to polar conversion"
  16. 75 print"  6) polar to rectangular conversion"
  17. 80 print"  7) english to metric conversions"
  18. 85 print"  8) metric to english conversions"
  19. 90 gosub755:poke198,0
  20. 95 get a$:if a$="" then95
  21. 100 a=val(a$)
  22. 105 on a goto125,245,405,560,765,990,1179,1404
  23. 110 if a$="[136]" then10
  24. 115 if a$="[140]" then25
  25. 120 goto95
  26. 125 print"[147]":poke53280,1:poke53281,1:d$="":w=22
  27. 130 print"[156]           decimal to binary "
  28. 135 print"[144]   enter decimal no.? ";:d$=""
  29. 137 if xx=12 then xx=0
  30. 138 if xx>6 then print" [157]";:goto 143
  31. 140 print"[164][157]";
  32. 143 get z$
  33. 145 if z$="m" then45
  34. 150 if z$="s" then245
  35. 155 if z$="[136]" then10
  36. 160 if z$="[140]" then25
  37. 165 if z$=chr$(20) then print:gosub755:gosub35:d$="":goto188
  38. 170 if z$=chr$(13) then print:s$=d$:gosub30:print"[145][145]":goto190
  39. 175 if len(d$)>4 then188
  40. 180 if z$<"0" or z$>"9" then188
  41. 185 print z$;:d$=d$+z$
  42. 188 xx=xx+1:goto 137
  43. 190 d=val(d$)
  44. 195 if d=0 or d>65535 then print:gosub35:d$="":goto140
  45. 200 gosub755
  46. 205 print:printtab(3)"[144]binary equivalent"
  47. 210 y=32768:z1=0
  48. 215 for x1=1 to 16
  49. 220 p=int(d/y):if p=-p then230
  50. 225 d=d-y
  51. 230 y=y/2
  52. 232 z1=z1+p:if z1=0 then 240
  53. 235 printtab(3)"[157]"p;:ifx1=4orx1=8orx1=12thenprint"";
  54. 240 next:print"":goto135
  55. 245 print"[147][144]":poke53280,1:poke53281,1:p=0:c$="":e$="":w=22
  56. 250 print"[156]           binary to decimal "
  57. 255 print"[144]   number of digits ? ";:p=0:c$="":e$=""
  58. 257 if xx>10 then xx=0
  59. 258 if xx>5 then print" [157]";:goto 263
  60. 260 print"[164][157]";
  61. 263 get b$
  62. 265 if b$="m" then45
  63. 270 if b$="s" then125
  64. 275 if b$="[136]" then10
  65. 280 if b$="[140]" then25
  66. 285 if b$=chr$(20) then print:gosub755:gosub35:c$="":goto307
  67. 290 if b$=chr$(13) then print:s$=c$:gosub30:print"[145][145]":goto310
  68. 295 if len(c$)>1 then307
  69. 300 if b$<"0" or b$>"9" then307
  70. 305 print b$;:c$=c$+b$
  71. 307 xx=xx+1:goto 257
  72. 310 c=val(c$):if c=0 or c>16 then print:gosub35:c$="":goto260
  73. 315 gosub755
  74. 320 print:print"[144]   enter binary no. ? ";:k=c
  75. 322 if xx>10 then xx=0
  76. 323 if xx>5 then print" [157]";:goto 327
  77. 325 print"[164][157]";
  78. 327 get a$
  79. 330 if a$="m" then45
  80. 335 if a$="s" then125
  81. 340 if a$="[136]" then10
  82. 345 if a$="[140]" then25
  83. 350 if a$=chr$(20) then print:gosub755:gosub35:c=k:p=0:e$="":goto380
  84. 355 if a$=chr$(13) then print:s$=e$:gosub30:print"[145][145]":goto385
  85. 360 if c=0 then380
  86. 365 if a$<>"0" and a$<>"1" then380
  87. 370 print a$;:e$=e$+a$:a=val(a$)
  88. 375 c=c-1:p=p+2^c*a
  89. 380 xx=xx+1:goto322
  90. 385 if c<>0 then print:gosub35:c=k:p=0:e$="":goto325
  91. 390 gosub755
  92. 395 print:printtab(2)"[144] decimal equivalent";
  93. 400 print p"":goto255
  94. 405 print"[147]":poke53280,3:poke53281,3:g$="":w=27:goto415
  95. 410 printtab(w)"[145]          [157][157][157][157][157][157][157][157][157][157]";:return
  96. 415 print"[156]         decimal to hexadecimal "
  97. 420 print"[144]        enter decimal no.? ";:g$=""
  98. 422 if xx>10 then xx=0
  99. 423 if xx>5 then print" [157]";:goto 428
  100. 425 print"[164][157]";
  101. 428 get f$
  102. 430 if f$="m" then45
  103. 435 if f$="s" then560
  104. 440 if f$="[136]" then10
  105. 445 if f$="[140]" then25
  106. 450 if f$=chr$(20) then print:gosub755:gosub410:g$="":goto472
  107. 455 if f$=chr$(13) then print:s$=g$:gosub30:print"[145][145]":goto475
  108. 460 if len(g$)>4 then472
  109. 465 if f$<"0" or f$>"9" then472
  110. 470 print f$;:g$=g$+f$
  111. 472 xx=xx+1:goto 422
  112. 475 g=val(g$)
  113. 480 if g=0 or g>65535 then print:gosub410:g$="":goto425
  114. 485 gosub755
  115. 490 print:printtab(4)"[144]hexadecimal equivalent";
  116. 495 h=4096:z1=0
  117. 500 for i=1 to 4
  118. 505 j=int(g/h):if j=-j then515
  119. 510 g=g-h*j
  120. 515 h=h/16:j$=str$(j)
  121. 520 if j=10 then j$=" a"
  122. 525 if j=11 then j$=" b"
  123. 530 if j=12 then j$=" c"
  124. 535 if j=13 then j$=" d"
  125. 540 if j=14 then j$=" e"
  126. 545 if j=15 then j$=" f"
  127. 547 z1=z1+j:if z1=0 then 555
  128. 550 print j$;
  129. 555 next:print"":goto420
  130. 560 print"[147]":poke53280,3:poke53281,3:q=0:n$="":t$="":w=27
  131. 565 print"[156]         hexadecimal to decimal "
  132. 570 print"[144]        number of digits ? ";:q=0:n$="":t$=""
  133. 572 if xx>10 then xx=0
  134. 573 if xx>5 then print" [157]";:goto 578
  135. 575 print"[164][157]";
  136. 578 get l$
  137. 580 if l$="m" then45
  138. 585 if l$="s" then405
  139. 590 if l$="[136]" then10
  140. 595 if l$="[140]" then25
  141. 600 if l$=chr$(20) then print:gosub755:gosub410:n$="":goto622
  142. 605 if l$=chr$(13) then print:s$=n$:gosub30:print"[145][145]":goto625
  143. 610 if len(n$)>0 then622
  144. 615 if l$<"1" or l$>"4" then622
  145. 620 print l$;:n$=n$+l$
  146. 622 xx=xx+1:goto 572
  147. 625 n=val(n$):ifn<1 or n>4then print:gosub410:n$="":goto575
  148. 630 gosub755
  149. 635 print:print"[144]    enter hexadecimal no.? ";:v=n
  150. 637 if xx>8 then xx=0
  151. 638 if xx>4 then print" [157]";:goto 643
  152. 640 print"[164][157]";
  153. 643 get r$
  154. 645 if r$="m" then45
  155. 650 if r$="s" then405
  156. 655 if r$="[136]" then10
  157. 660 if r$="[140]" then25
  158. 665 if r$=chr$(20) then print:gosub755:gosub410:n=v:q=0:t$="":goto730
  159. 670 if r$=chr$(13) then print:s$=t$:gosub30:print"[145][145]":goto735
  160. 675 if n=0 then730
  161. 680 if r$="a" or r$="b" or r$="c" or r$="d" or r$="e" or r$="f"then690
  162. 685 if r$<"0" or r$>"9" then730
  163. 690 print r$;:t$=t$+r$:r=val(r$)
  164. 695 if r$="a" then r=10
  165. 700 if r$="b" then r=11
  166. 705 if r$="c" then r=12
  167. 710 if r$="d" then r=13
  168. 715 if r$="e" then r=14
  169. 720 if r$="f" then r=15
  170. 725 n=n-1:q=q+16^n*r
  171. 730 xx=xx+1:goto 637
  172. 735 if n<>0 then print:gosub410:n=v:q=0:t$="":goto640
  173. 740 gosub755
  174. 745 print:printtab(2)"[144]      decimal equivalent";
  175. 750 print q"":goto570
  176. 755 pokesd+5,8:pokesd+6,240:pokesd,0:pokesd+1,90:pokesd+4,17:fors=1to100:next
  177. 760 pokesd+4,0:pokesd,0:pokesd+1,0:return
  178. 765 print"[147]":poke53280,0:poke53281,0:o$="":u$="":w=21
  179. 770 print"[156]          rectangular to polar "
  180. 775 print"      x coordinate ? [154]";:o$="":u$=""
  181. 777 if xx>10 then xx=0
  182. 778 if xx>5 then print" [157]";:goto 783
  183. 780 print"[164][157]";
  184. 783 get a$
  185. 785 if a$="m" then45
  186. 790 if a$="s" then990
  187. 795 if a$="[136]" then10
  188. 800 if a$="[140]" then25
  189. 805 if a$=chr$(20) then print:gosub755:gosub35:o$="":goto832
  190. 810 if a$=chr$(13) then print:s$=o$:gosub30:print"[145][145]":goto835
  191. 815 if len(o$)>6 then832
  192. 820 if a$="." or a$="-" then830
  193. 825 if a$<"0" or a$>"9" then832
  194. 830 print a$;:o$=o$+a$
  195. 832 xx=xx+1:goto 777
  196. 835 o=val(o$):ifo$=""or(o<-999.99 or o>999.99)then print:gosub35:o$="":goto780
  197. 840 if o$<>right$(str$(o),len(o$))then print:gosub35:o$="":goto780
  198. 845 gosub755
  199. 850 print"      y coordinate ? [154]";:u$=""
  200. 852 if xx>10 then xx=0
  201. 853 if xx>5 then print" [157]";:goto 858
  202. 855 print"[164][157]";
  203. 858 get a$
  204. 860 if a$="m" then45
  205. 865 if a$="s" then990
  206. 870 if a$="[136]" then10
  207. 875 if a$="[140]" then25
  208. 880 if a$=chr$(20) then print:gosub755:gosub35:u$="":goto907
  209. 885 if a$=chr$(13) then print:s$=u$:gosub30:print"[145][145]":goto910
  210. 890 if len(u$)>6 then907
  211. 895 if a$="." or a$="-"then905
  212. 900 if a$<"0" or a$>"9" then907
  213. 905 print a$;:u$=u$+a$
  214. 907 xx=xx+1:goto 852
  215. 910 u=val(u$):ifu$=""or(u<-999.99 or u>999.99)then print:gosub35:u$="":goto855
  216. 915 if u$<>right$(str$(u),len(u$))then print:gosub35:u$="":goto855
  217. 920 gosub755
  218. 925 v=sqr(o^2+u^2)
  219. 930 if o=0 then960
  220. 935 y=atn(u/o)*180/(NULL)
  221. 940 if o<0 and u<0 then y=y+180
  222. 945 if o<0 and u>=0 then y=180+y
  223. 950 if o>0 and u<0 then y=360+y
  224. 955 goto970
  225. 960 if u>0 then y=90
  226. 965 if u<0 then y=270
  227. 970 v1=abs(v)*100+.5:v=sgn(v)*int(v1)/100
  228. 975 y1=abs(y)*100+.5:y=sgn(y)*int(y1)/100
  229. 980 print"    polar equivalent[158]";v"[157]<"y:v=0:y=0
  230. 985 print"":goto775
  231. 990 print"[147]":poke53280,0:poke53281,0:o$="":u$="":w=21
  232. 995 print"[156]          polar to rectangular "
  233. 1000 print"           modulus ? [154]";:o$="":u$=""
  234. 1002 if xx>10 then xx=0
  235. 1003 if xx>5 then print" [157]